/*************************************************************************
	> File Name: client.h
	> Author: xuwenlong
	> Mail: myxuan475@126.com 
	> Created Time: 2018年09月17日 星期一 15时02分16秒
 ************************************************************************/
#ifndef __SERVER_CLIENT_H__
#define __SERVER_CLIENT_H__
#include <iostream>
#include <sys/select.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <string.h>
#include <event.h>
#include <stdlib.h>
#include <utils/threads/thread.h>
#include <utils/threads/thread_delegate.h>
#include <defines.h>
#include <transport/transport.h>
#include <transport/remote/server/server.h>
#include <transport/remote/server/user.h>
#include "jsonrpchandler.h"

class DasServer;

class Client:public User
{
public:
    Client(DasServer *pServer);
    virtual ~Client();

    typedef struct {
        int dev_count;
        U64  acq_last;
        U64  up_last;
        int  up_fail;
        int acq_fail;
        time_t uptime;
    }cl_report;

    virtual BOOL OnReceiveJson(
            S32 index,
            DAS_RESULT status,
            const string &method, const Json::Value &result);

    DAS_RESULT registerAcquisitor(const Json::Value &params,
                           Json::Value &result);
    DAS_RESULT uploadFile(const Json::Value &params,
                           Json::Value &result);

    DAS_RESULT reportError(const Json::Value &params);

    S32 SendJsonRpc(JsonRpcInterface *_interface,const std::string &method, const Json::Value &params);
    void startDaemon();

    Json::Value JsonAcquisitor();
    const std::string &CompanyName();
    const std::string &GatewayId();

    bool IsRegister();
    int  CheckCount();

    bool IsIdEqual(const std::string &strId);

    string Report(const string &mark);

    int GetPort(int type);

private:
    string timedifftostr(U64 min);
    string timetostr(time_t t);
    int getport(const string &url);
    Json::Value json_string_to_json(const char *str);
private:
    std::string m_strId;
    std::string m_version;
    std::string m_company;
    std::string m_ipAddr;
    S32   m_iTelId;
    S32    m_icheck;

    S32  m_ftpPort;
    S32  m_telnetPort;
//    JsonRpcInterface *m_jsonRpcInterface;
};

#endif
